package com.bzoa.api.control;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bzoa.api.dto.UserListPageDTO;
import com.bzoa.api.entity.User;
import com.bzoa.api.service.UserService;
import com.springboot.common.entity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author lands
 * @Date 2023/3/6 10:32
 * @Description 用户相关接口
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("getUser")
    public ResponseResult getUser(String id) {
        User user = userService.getUser(id);
        if (user == null) {
            return ResponseResult.error("找不到用户");
        } else {
            return ResponseResult.ok(user);
        }
    }

    /**
     * @param page
     * @param pageSize
     * @param mobile
     * @param nickname
     * @return
     */
    @GetMapping("/getUserList")
    public ResponseResult getUserList(Integer page, Integer pageSize, String mobile, String nickname) {
        return ResponseResult.ok(userService.getUserListPage(page, pageSize, mobile, nickname));
    }

    /**
     * 批量导入用户 ，默认密码000000
     *
     * @param user
     * @return
     */
    @PostMapping("importUser")
    public ResponseResult importUser(@RequestBody User user) {
        return userService.login(user.getUsername(), user.getPassword());
    }
}